
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>留言板-学并思</title>
    <link href="./template/css/bootstrap.min.css" rel="stylesheet">
    <link href="./template/css/bootstrap-theme.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    
  </head>

  <body>

    <!-- Fixed navbar -->
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">留言板</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li role="separator" class="divider"></li>
                <li class="dropdown-header">Nav header</li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="container theme-showcase" role="main">	
    	

      <div class="page-header">
        <h1></h1>
      </div>
      <div class="row">
        
      </div>
      <div class="row">
        <style type="text/css">
            .blue {
              color: blue;
            }
            .red {
              color: red;
            }
        </style>
      	<form action="./addUser.php" method="post" class="form-horizontal">
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-4">
              <input type="text" class="form-control" name="nickname" placeholder="用户名">
            </div>
            <div class="col-sm-6 info">
            </div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">邮箱</label>
            <div class="col-sm-4">
              <input type="email" class="form-control" name="email" placeholder="邮箱">
            </div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">手机</label>
            <div class="col-sm-4">
              <input type="text" class="form-control" name="phone" placeholder="手机">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-4">
              <input type="password" class="form-control" name="password" placeholder="密码">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPassword3" class="col-sm-2 control-label">重复密码</label>
            <div class="col-sm-4">
              <input type="password" class="form-control" name="repassword" placeholder="密码">
            </div>
          </div>
          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-4">
              <button type="submit" class="btn btn-success">注册</button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </body>
  <script type="text/javascript">
    $(function () {
        $('input[name=nickname]').focus(function(){

          $(this).css({border:"1px solid #CCCCCC"});
          $(this).parent().siblings('.info').html('')
          
        })

        $('input[name=nickname]').blur(function () {
            aaa = $(this).val();
            that = $(this);

            $.ajax({
              url: './checkreg.php',
              type: 'POST',
              dataType: 'json',
              data: {nickname: aaa,id:10,age:20},
            })
            .done(function(respson) {

              if(respson.error==1){

                that.css({border:"1px solid red"});

                that.parent().siblings('.info').html('<span class="red">'+respson.info+'</span>')
              }else{

                that.parent().siblings('.info').html('<span class="blue">'+respson.info+'</span>')
              }
                // alert(respson.error)
                // alert(respson.info)
                
            })
            .fail(function() {
              alert("通讯异常")
            })
            
            
        })
    })
  </script>
</html>
